package com.ts.modules.movie.controller;

import com.ts.common.entity.ResponseResult;
import com.ts.common.utils.Result;
import com.ts.movie.controller.MovieController;
import com.ts.movie.dto.MovieDTO;
import com.ts.movie.entity.Movie;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ts.feign.api.MovieMgtService;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/movie-mgt")

public class MovieMgtController {
    @Autowired
    MovieMgtService movieFeignServie;

    @GetMapping("/action/query")
    public Result query() {
        log.debug("list:{}", movieFeignServie);
        ResponseResult resp = movieFeignServie.query();
        List<MovieDTO> data = (List<MovieDTO>) resp.get("data");
        return new Result<List<MovieDTO>>().ok(data);
    }

    @GetMapping("/{id}")
    public Result query(@PathVariable Integer id) {
        ResponseResult resp = movieFeignServie.query(id);
        Object data = resp.get("data");
        return new Result().ok(data);
    }


    @PostMapping
    public Result add(@RequestBody MovieDTO movie) {
        log.debug("movie==============:{}", movie);
        movieFeignServie.add(movie);
        return new Result();
    }

    @PostMapping("/action/update")
    public Result update(@RequestBody MovieDTO movie) {
        movieFeignServie.update(movie);
        return new Result();
    }

    @DeleteMapping("/action/delete")
    public Result update(@RequestBody List<Integer> ids) {
        movieFeignServie.delete(ids);
        return new Result();
    }
}
